/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2023-11-24 15:38:32
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2023-11-24 15:54:10
 * @FilePath: \WingsUpdater-main\inc\DataTransmission\DataTransmissionUdp.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

#pragma once
#include "IDataTransmission.h"
#include "Platform.h"
#include <thread>
#include <atomic>

class DataTransmissionUdp final: public IDataTransmission 
{
public:
    DataTransmissionUdp() = default;
    ~DataTransmissionUdp()override;
    virtual Result init(const std::initializer_list<void *> attr)override;
    virtual Result transmit(const void *src, const size_t size)override;
    virtual void release(const void *item)override;
private:
    void run();
    void deinit();
private:
    uint16_t m_localPort = 6153;
    int m_sock = -1;
    size_t m_headerSize = 20;
    uint16_t m_type;
    size_t m_sliceSize = 4096;
    sockaddr_in m_peerAddr;
    uint32_t m_peerAddrSize;
    std::atomic<bool> m_workerExitFlag = true;
    std::thread m_worker;
};
